package cn.jobstart.service.impl;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import cn.jobstart.modelExt.AdminJobManagerExt;
import cn.jobstart.dao.IAdminJobManagerDao;
import cn.jobstart.searchExt.AdminJobManagerSearchExt;
import cn.jobstart.pubInter.IBaseDao;
import cn.jobstart.pubInter.AbstractBaseService;
import cn.jobstart.service.IAdminJobManagerService;
import lombok.extern.slf4j.Slf4j;
import cn.jobstart.common.StringUtil;
import cn.jobstart.common.SkList;
import cn.jobstart.pubInter.exception.SkException;

import java.util.List;
import java.util.stream.Collectors;


/**
*    @author sunke
*    @Date 2023-10-04 23:18:14
*    @description AdminJobManagerService      职位管理人员
*/
@Service(value = "adminJobManagerService")
@Slf4j
public class AdminJobManagerServiceImpl extends AbstractBaseService<AdminJobManagerExt, AdminJobManagerSearchExt,String> implements IAdminJobManagerService {

    @Resource(name = "adminJobManagerDao")
    private IAdminJobManagerDao adminJobManagerDao;

    @Override
    public IBaseDao<AdminJobManagerExt, AdminJobManagerSearchExt,String> getDao() {
        return adminJobManagerDao;
    }


    /**
     * 得到用户的所有职位ID
     *
     * @param adminId
     * @return
     * @throws SkException
     */
    @Override
    public List<String> getJobIdsByAdminId(String adminId) throws SkException {
        if(StringUtil.isNullOrEmpty(adminId)){
            return null;
        }

        AdminJobManagerSearchExt search=AdminJobManagerSearchExt.getInstance();
        search.setAdminIdEq(adminId);
        List<AdminJobManagerExt> list=getAllList(search);
        if(StringUtil.isNullOrEmpty(list)){
            return null;
        }


        return list.stream().map(AdminJobManagerExt::getAdminJobId).distinct().collect(Collectors.toList());
    }

    /**
     * 清空
     *
     * @param adminJobId
     * @throws SkException
     */
    @Override
    public void clearByAdminJobId(String adminJobId) throws SkException {
        if(StringUtil.isNullOrEmpty(adminJobId)){
            return;
        }

        batchDeleteBySearch(AdminJobManagerSearchExt.getInstance().setAdminJobIdEq(adminJobId));


    }
}